package com.qf.agro.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.agro.pojo.SysModule;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 菜单dao
 * @author 千锋健哥
 */
@Repository
public interface ModelMapper extends BaseMapper<SysModule> {

    /**
     * 根据用户id, 查询菜单列表
     * @param userId
     * @return
     */
    @Select("select e.* " +
            "from sa_sys_user a  " +
            "left join sa_sys_user_role b on a.id = b.user_id " +
            "left join sa_sys_role c on c.id = b.role_id " +
            "left join sa_sys_role_module d on d.role_id = c.id " +
            "left join sa_sys_module e on e.id = d.module_id " +
            "where a.id=#{id}")
    public List<SysModule> findListByUserId(@Param("id") Long userId);

    @Select("select e.* " +
            "from sa_sys_user a  " +
            "left join sa_sys_user_role b on a.id = b.user_id " +
            "left join sa_sys_role c on c.id = b.role_id " +
            "left join sa_sys_role_module d on d.role_id = c.id " +
            "left join sa_sys_module e on e.id = d.module_id " +
            "where a.id=#{id} and e.is_leaf=0 ")
    public List<SysModule> findParentListByUserId(@Param("id") Long userId);
}
